<?php
/*
 * Created on Feb 23, 2010
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
echo '<link href="css/popup/default.css" type="text/css" rel="stylesheet">'; 
echo '<link href="css/popup/alphacube.css" type="text/css" rel="stylesheet">'; 

echo '<script type="text/javascript" src="js/windowjs/effects.js"></script>';
echo '<script type="text/javascript" src="js/windowjs/window.js"></script>';
echo '<script type="text/javascript" src="js/windowjs/window_effects.js"></script>';
echo '<script type="text/javascript" src="js/windowjs/debug.js"></script>';


$start = $_GET['start'] ? $_GET['start'] : 0;
if (strlen($start) > 0 and !is_numeric($start)){
	echo "Data Error"; exit;
}
$eu = ($start - 0); 
$limit = MAX_RECORD_ESTATE;                                 
$this1 = $eu + $limit; 
$back = $eu - $limit; 
$next = $eu + $limit;

$type = $_GET['type'] ? $_GET['type'] : "";

if ($type == 'transaction') {
	$transactionId  = $_GET['transactionId'] ? $_GET['transactionId'] : '';
	$items = $itemModel->getItemByTransactionId($transactionId, $eu, $limit);
	$num = $itemModel->countItemByTransactionId($transactionId);
	$item = $transactionModel->getTransById($transactionId);
	$categoryParam = 'transactionId='.$transactionId.'';
	$currentPage = 'transaction.php';
} elseif ($type == 'cityregion') {
	$cityRegionId = $_GET['cityregionid'] ? $_GET['cityregionid'] : '';  
	$items = $cityModel->getCitiesRegionById($cityRegionId, $eu, $limit);
	$item = $cityModel->getRegionById($cityRegionId);  
	$num = $cityModel->countCitiesRegionById($cityRegionId);
	$categoryParam = 'cityregionid='.$cityRegionId.'';
	$currentPage = 'cityregion.php';
} elseif (substr($type, 0, 8) == 'category') {
	$typeId = $_GET['typeid'] ? $_GET['typeid'] : '';  
	$items = $itemModel->getItemByTypeId($typeId, $eu, $limit); 
	$item = $itemModel->getTypeName($typeId);  
	$num = $itemModel->countItemByTypeId($typeId);  
	$categoryParam = 'typeid='.$typeId; 
	$currentPage = 'typedetail.php'; 
}

echo '<div class="li_content" style="padding-top:4px;">';
echo '<script type="text/javascript" src="js/prototype-1.6.0.2.js"></script>';
echo '<script type="text/javascript" src="js/previewpopup.js"></script>';
	
if ($num > 0) {
	echo '<table>';
			echo '<thead style="">';
				echo '<th style="width: 375px; background-color: #004B80; font-size: 11px;">'.$item['name'].'</th>';
				echo '<th style="width: 42px; background-color: #004B80; font-size: 11px;">Ảnh</th>';
				echo '<th style="width: 70px; background-color: #004B80; font-size: 11px;">Vị trí</th>';
				echo '<th style="width: 75px; background-color: #004B80; font-size: 11px;">Diện tích</th>';
				echo '<th style="background-color: #004B80; font-size: 11px;">Giá</th>';
				echo '<th style="width: 69px; background-color: #004B80; font-size: 11px;">Ngày đăng</th>';
			echo '</thead>';
			$i = 0;
			while ($item = $itemModel->getArrayNameInfos($items)) {
				$altrow = "";
				if ($i % 2) {
					$altrow = 'style="background-color: #FFFFE1"';
				}
				echo '<tr '.$altrow.' class="cityRegion">';
					echo '<td>';
						echo '<a href="itemrestatedetail.php?itemid='.$item['id'].'&type='.$type.'&'.$categoryParam.'">'.$item['title'].'</a>';
						if ($item['isSpecial'] == 1) {
							echo '<img src="images/hot.gif" width="28" height="16" border="0"/>';
						}
					echo '</td>';
					echo '<td>'; 
						$fileName = 'img/upload/item/'.$item["image"]; 
						echo '<a onclick = "openDialogAdd(\'popup'.$item['id'].'\');" href="javascript:void(0);">';
							echo '<img src="images/home-icon.png" width="16" height="16" class="photosearch" />';
						echo '</a>';
						echo '<div id="popup'.$item['id'].'" style="display:none;">';
				 			echo '<h3>'.truncate($item['title'], 50).'</h3>';
							if ($item['image'] && file_exists($fileName)) {
								echo '<img class="photo" alt="" src="'.$fileName.'" width="300px" height="345px" />';
							} else {
								echo '<img class="photo" alt="" src="img/NoPhotoAvailable.jpg" width="300px" height="345px" />';
							}
				 		echo '</div>';		
					echo '</td>';
					echo '<td>'.$item['place'].'</td>';
					echo '<td>'.$item['size'].'</td>';
					echo '<td>'.$item["price"].'</td>';
					echo '<td>'.ConvertSQLDate($item["createDate"]).'</td>';					
				echo '</tr>';
				$i++;
			}
			echo '</table>';
			echo '<br/>';
		} else {
		echo '<div class="alert-message">Hiện tại mục này chưa có bài đăng!</div>';
	}
					
	// Paginate
	if ($num > $limit) {
		echo '<div id="pager">Trang ';
		if ($back >= 0) {
			echo '<a href="'.$currentPage.'?'.$categoryParam.'&start='.$back.'&type='.$type.'"><img src="img/icons/arrow_left.gif" width="16" height="16" /></a>';
		}
		$i = 0;
		$l = 1;
		for ($i = 0; $i < $num; $i = $i + $limit) {
			if ($i <> $eu) {
				echo " <a href='".$currentPage."?$categoryParam&start=".$i."&type=".$type."'><font face='Verdana' size='2'>$l</font></a> ";
			}else { 
				echo '<span style="font-size: 18px; color: red;">'.$l.'</span>';			
			}
			$l = $l + 1;
		}
		if($this1 < $num) {
			echo '<a href="'.$currentPage.'?'.$categoryParam.'&start='.$next.'&type='.$type.'"><img src="img/icons/arrow_right.gif" width="16" height="16" /></a>';
		}
		echo ' Tổng cộng <strong>'.$num.'</strong> thông tin';
		echo '</div>';
	}
	// End paginate
	
	// My include
	echo '<hr><br/ >';
	include '_lastnew.php';
	// End include

echo '</div>';

?>
<script type="text/javascript">
	function openDialogAdd (divid ) {  
		Dialog.alert($ (divid).innerHTML, { className: "alphacube", width: 340, height: 420, okLabel: "Đóng" });
	}
</script>